/**
 * 此文件为模拟请求数据get请求
 */

/**
 * 请求数据
 * @param {*} field 数据变量名称
 * @param {*} params 相关参数
 * @returns 
 */
function requestInterface(field, params = {}) {
    return new Promise((resolve, reject) => {
        analogInterface(field, params).then(res => {
            resolve(res);
            if (res) {
                resolve(res);
            } else {
                reject(res);
                ice.pop({
                    icon: "fail",
                    content: "当前查询为空数据～"
                })
            }
        }).catch(err => {
            reject(err);
            ice.pop({
                icon: "fail",
                content: err
            })
        })
    })
}


/**
 * 模拟请求接口
 * @param {*} field 数据变量名称
 * @param {*} params 相关参数
 */
function analogInterface(field, params = {}) {
    return new Promise((resolve, reject) => {
        if (!field) {
            reject("请求字段不能为空～");
            return;
        }
        const databaseTable = {
            deviceRecords: JSON.parse(JSON.stringify(deviceRecords)),
            videoRecords: JSON.parse(JSON.stringify(videoRecords))
        }
        let filterDataList = databaseTable[field]; // 过滤设备源数据
        // 根据参数条件过滤数据
        if (Object.keys(params).length) {
            filterDataList = databaseTable[field].filter(item => {
                for (const key in params) {
                    if (key == "currPage" || key == "pageSize") {
                        return true;
                    }
                    if (item[key] !== params[key]) {
                        return false;
                    }
                }
                return true;
            })
            for (const key in params) {
                if (key == "pageSize") {
                    filterDataList = filterDataList.slice(0, params[key])
                }
            }
        }
        console.log("%c数据查询完毕~", "color:#659F59");
        resolve(filterDataList);
    })
}